package com.example.todo.mapper;

import com.example.todo.model.Knowledge;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface KnowledgeMapper {

    @Select("SELECT * FROM knowledge ORDER BY create_time DESC")
    List<Knowledge> findAll();
    
    @Select("SELECT * FROM knowledge WHERE id = #{id}")
    Knowledge findById(Long id);
    
    @Insert("INSERT INTO knowledge (title, content, image_url) VALUES (#{title}, #{content}, #{imageUrl})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insert(Knowledge knowledge);
    
    @Update("UPDATE knowledge SET title = #{title}, content = #{content}, image_url = #{imageUrl} WHERE id = #{id}")
    void update(Knowledge knowledge);
    
    @Delete("DELETE FROM knowledge WHERE id = #{id}")
    void delete(Long id);
} 